//#include "gem.h"
//#include "cup.h"
#include "board.h"
#include "highscore.h"
#include "mancala_ai.h"

//TODO was failing without exporting it to 0 or 1
//export MALLOC_CHECK_=0
int main(int argc, char** argv){
  Board & board = *(new Board());
  board.print_board();
  board.set_turn(0);
  if(!board.move(2)){
    cout << "Player 1 should not have another turn" << endl;
  }
  else{
    cout << "Failure" << endl;
  }
  board.print_board();
  board.set_turn(1);
  if(board.move(10)){
    cout << "Player 2 should have another turn" << endl;
  }
  else{
    cout << "Failure!" << endl;
  }
  board.print_board();
  board.move(12);
  cout << "==========>>>>>MOVE 12 BY PLAYER 1<<<<<<====================" << endl;
  board.print_board();
  board.set_turn(0);
  board.move(3);
  board.print_board();
  cout << "Mancala for player 0 should have 1 gem" << endl;
  board.move(2);
  board.print_board();
  cout << "Mancala for player 0 should have 6 gem" << endl;
  cout << "Player 0 score should be 30, got: " << board.get_scores(0) << endl;
  cout << "Player 1 score should be 18, got: " << board.get_scores(1) << endl;
  cout << "Won by should be -1, got " << board.won_by() << endl;
  
  board.move(1);
  board.move(2);
  board.move(3);
  board.move(4);
  board.move(5);
  board.move(6);
  board.move(1);
  board.move(2);
  board.move(3);
  board.move(4);
  board.move(5);
  board.move(6);
  board.print_board();
  cout << "won by should be 0, got " << board.won_by() << endl;
  
  Highscore::add("Stanislav", 5);
  Highscore::add("Stanislav", 2);
  Highscore::add("Jack", 8);
  Highscore::add("Even", 2);
  Highscore::add("Miraslav!!!!!!!!!!!!!!!", 1);
  Highscore::add("Jack!!!", 1);
  Score** scores = new Score*[5];
  Highscore::top(5, scores);
  cout << "Top 10 scores are: " << endl;
  for(int i=0; i<5; ++i){
    cout << "name: " <<  scores[i] -> name << "score: " << scores[i] -> score << endl;
  }
  Highscore::clear_scores();

  cout << "Testing AI" << endl;
  MancalaAi & ai = *(new MancalaAi(1));
  board = *(new Board());
  board.print_board();
  cout << "Getting move" << endl;
  int i = ai.next_move();
  cout << "Ai wants to move this: " << i << endl;
}
